<?php
!defined('P_W') && exit('Forbidden');
require_once MODE . '/base/basehelper.php';
/**
 * 纪纪人相关的helper
 * @author suqian
 */
class PW_BrokerHelper extends BaseHelper {
	

	/**
	 * 取得经纪人module
	 *@param int $uid 经纪人
	 *@param int $ifbuild 是否组装module
	 *@param int $ifuser  是否同时经纪人论坛用户相关信息
	 *@return object;
	 */
	function getBrokerModule($uid,$ifbuild=0,$ifuser = 0){
		$brokerService = $this->getBrokerService();
		$brokerModule =  $brokerService->getBrokerModule($uid);
		$ifbuild && $brokerModule = $this->buildBrokerModule($brokerModule);
		if($ifuser){
			$userinfo = $this->getUserInfo($uid);
			$brokerModule->brokerInfo = $userinfo;
		}
		return $brokerModule;
	}
	/**
	 * 经纪人module数据组装
	 *@param object $module 经纪人module
	 *@return object;
	 */
	function buildBrokerModule($module){
		if(!is_object($module)){
			Error::addError("{$module}不是一个对象");
		}
		$houseFieldsService = $this->getHouseFieldsService();
		$plateField = $houseFieldsService->getCompsiteFieldsByType('plate');//所在商圈
		$newvery = '';
		$newverypic = '';
		$sendImagePath = 'mode/house/images/sendhand/verify/';
		foreach($module->verifyInfo as $value){
			if($value['check']){
				$tmp = '已通过'.$value['name'];
				$path = $sendImagePath.$value['icon'];
				$tmppic = "<img src='$path' alt='$tmp' style='cursor:pointer' class='icon-img' title='$tmp'/> ";
				$newvery .= $newvery ? ','. $tmp : $tmp;
				$newverypic .= $tmppic;
			}
		}
		$newplate = '';
		!is_array($module->plate) && $module->plate = array();
		foreach($module->plate as $value){
			$tmp = $plateField[$value];
			$newplate .= $newplate ? ','. $tmp : $tmp;
		}
				
		$module->newvery = $newvery;
		$module->newverypic = $newverypic;
		$module->newplate = $newplate;
		return $module;
		
	}
	
	function getUserInfo($uid){
		require R_P.'require/showimg.php';
		$userService = $this->getUserService();
		$user = $userService->get($uid,true,true);
		$user['faceurl'] = showfacedesign($user['icon'],1,'m'); 
		$user['regdate'] =  get_date($user['regdate'],'Y-m-d');
		$user['lastvisit'] =  get_date($user['lastvisit'],'Y-m-d');
		return $user;
	}
	
}